package main

func Encode(v uint32) []byte {
	var buf []byte
	for v > 0x7f {
		x := byte(v&0x7f | 0x80)
		buf = append(buf, x)
		v = v >> 7
	}
	buf = append(buf, byte(v))
	return buf
}

func Decode(buf []byte) uint32 {
	var v uint32
	shift := 0
	for _, x := range buf {
		v |= uint32(x&0x7f) << shift
		shift += 7
		if x&0x80 == 0 {
			break
		}
	}
	return v
}

func main() {
	buf := Encode(123456)
	x := Decode(buf)
	println(x)
}
